/**
 * Created by yang on 15/3/6.
 */
var nodemailer = require('nodemailer');

var mailConfig  = {
    name: 'your_project robot',
    config:{
        service: "QQ",
        host: "smtp.qq.com", //这里选用的是１６３邮箱代发，可改为gmail等
        port:465,
        secureConnection: true,
        auth: {
            user: "robot@xx.com", // 邮箱账号
            pass: "youpassword" // 邮箱密码
        }
    }
};

var smtpTransport = nodemailer.createTransport("SMTP",mailConfig.config);



function sendMail(to,subject, html) {
    var mailOptions = {
        from: [mailConfig.name, mailConfig.config.auth.user].join(' '),
        to: to,
        subject: subject,
        html: html
    };

    smtpTransport.sendMail(mailOptions, function(error, response){
        if (error) {
            console.log(error);
        } else {
            console.log('Message sent: ' + response.message);
        }
        smtpTransport.close();
    });
};

module.exports = sendMail;
